package Thread.choujiang;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Callable;

public class MyCallAble implements Callable<Integer> {

    ArrayList<Integer> list;

    public MyCallAble(ArrayList<Integer> list) {
        this.list = list;
    }

    @Override
    public Integer call() throws Exception {
        ArrayList<Integer> boxlist = new ArrayList<>();
        while (true) {
            synchronized (MyCallAble.class) {
                if (list.size() == 0) {
                    System.out.println(boxlist+"------"+Thread.currentThread().getName());

                    break;
                } else {
                    Collections.shuffle(list);
                    int e = list.get(0);
                    int prize = list.remove(0);
                    boxlist.add(prize);
                }
                Thread.sleep(100);
            }

        }
        if (boxlist.size() ==0){
            return  null;
        }else {
            return Collections.max(boxlist);
        }

    }
}
